﻿<?php require_once('../Connections/hitekforyou.php'); ?>
<?php
require_once('checklogin.php');
error_reporting(0);
// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Load the required classes
require_once('../includes/tfi/TFI.php');
require_once('../includes/tso/TSO.php');
require_once('../includes/nav/NAV.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

// Make unified connection variable
$conn_hitekforyou = new KT_connection($hitekforyou, $database_hitekforyou);



if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

// Filter
$tfi_listchitietdonhang1 = new TFI_TableFilter($conn_hitekforyou, "tfi_listchitietdonhang1");
$tfi_listchitietdonhang1->addColumn("chitietdonhang.idChitiet", "NUMERIC_TYPE", "idChitiet", "=");
$tfi_listchitietdonhang1->addColumn("donhang.idDH", "NUMERIC_TYPE", "idDH", "=");
$tfi_listchitietdonhang1->addColumn("sanpham.idSP", "NUMERIC_TYPE", "idSP", "=");
$tfi_listchitietdonhang1->addColumn("chitietdonhang.SoLuong", "NUMERIC_TYPE", "SoLuong", "=");
$tfi_listchitietdonhang1->addColumn("sanpham1.DonGia", "STRING_TYPE", "DonGia", "%");
$tfi_listchitietdonhang1->Execute();

// Sorter
$tso_listchitietdonhang1 = new TSO_TableSorter("rschitietdonhang1", "tso_listchitietdonhang1");
$tso_listchitietdonhang1->addColumn("chitietdonhang.idChitiet");
$tso_listchitietdonhang1->addColumn("donhang.idDH");
$tso_listchitietdonhang1->addColumn("sanpham.TenSP");
$tso_listchitietdonhang1->addColumn("chitietdonhang.SoLuong");
$tso_listchitietdonhang1->addColumn("sanpham1.DonGia");
$tso_listchitietdonhang1->setDefault("chitietdonhang.idChitiet");
$tso_listchitietdonhang1->Execute();

// Navigation
$nav_listchitietdonhang1 = new NAV_Regular("nav_listchitietdonhang1", "rschitietdonhang1", "../", $_SERVER['PHP_SELF'], 10);

mysql_select_db($database_hitekforyou, $hitekforyou);
$query_Recordset1 = "SELECT TenKH, idKH FROM khachhang ORDER BY TenKH";
$Recordset1 = mysql_query($query_Recordset1, $hitekforyou) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_hitekforyou, $hitekforyou);
$query_Recordset2 = "SELECT idDH, idDH FROM donhang ORDER BY idDH";
$Recordset2 = mysql_query($query_Recordset2, $hitekforyou) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

mysql_select_db($database_hitekforyou, $hitekforyou);
$query_Recordset3 = "SELECT TenSP, idSP FROM sanpham ORDER BY TenSP";
$Recordset3 = mysql_query($query_Recordset3, $hitekforyou) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);

mysql_select_db($database_hitekforyou, $hitekforyou);
$query_Recordset4 = "SELECT DonGia, DonGia FROM sanpham ORDER BY DonGia";
$Recordset4 = mysql_query($query_Recordset4, $hitekforyou) or die(mysql_error());
$row_Recordset4 = mysql_fetch_assoc($Recordset4);
$totalRows_Recordset4 = mysql_num_rows($Recordset4);

//NeXTenesio3 Special List Recordset
$maxRows_rschitietdonhang1 = $_SESSION['max_rows_nav_listchitietdonhang1'];
$pageNum_rschitietdonhang1 = 0;
if (isset($_GET['pageNum_rschitietdonhang1'])) {
  $pageNum_rschitietdonhang1 = $_GET['pageNum_rschitietdonhang1'];
}
$startRow_rschitietdonhang1 = $pageNum_rschitietdonhang1 * $maxRows_rschitietdonhang1;

// Defining List Recordset variable
$NXTFilter_rschitietdonhang1 = "1=1";
if (isset($_SESSION['filter_tfi_listchitietdonhang1'])) {
  $NXTFilter_rschitietdonhang1 = $_SESSION['filter_tfi_listchitietdonhang1'];
}
// Defining List Recordset variable
$NXTSort_rschitietdonhang1 = "chitietdonhang.idChitiet";
if (isset($_SESSION['sorter_tso_listchitietdonhang1'])) {
  $NXTSort_rschitietdonhang1 = $_SESSION['sorter_tso_listchitietdonhang1'];
}
mysql_select_db($database_hitekforyou, $hitekforyou);

$query_rschitietdonhang1 = "SELECT chitietdonhang.idChitiet, donhang.idDH AS idDH, sanpham.TenSP AS idSP, chitietdonhang.SoLuong, sanpham1.DonGia FROM ((chitietdonhang LEFT JOIN donhang ON chitietdonhang.idDH = donhang.idDH) LEFT JOIN sanpham ON chitietdonhang.idSP = sanpham.idSP) LEFT JOIN sanpham AS sanpham1 ON chitietdonhang.DonGia = sanpham1.DonGia WHERE {$NXTFilter_rschitietdonhang1} ORDER BY {$NXTSort_rschitietdonhang1}";
$query_limit_rschitietdonhang1 = sprintf("%s LIMIT %d, %d", $query_rschitietdonhang1, $startRow_rschitietdonhang1, $maxRows_rschitietdonhang1);
$rschitietdonhang1 = mysql_query($query_limit_rschitietdonhang1, $hitekforyou) or die(mysql_error());
$row_rschitietdonhang1 = mysql_fetch_assoc($rschitietdonhang1);

if (isset($_GET['totalRows_rschitietdonhang1'])) {
  $totalRows_rschitietdonhang1 = $_GET['totalRows_rschitietdonhang1'];
} else {
  $all_rschitietdonhang1 = mysql_query($query_rschitietdonhang1);
  $totalRows_rschitietdonhang1 = mysql_num_rows($all_rschitietdonhang1);
}
$totalPages_rschitietdonhang1 = ceil($totalRows_rschitietdonhang1/$maxRows_rschitietdonhang1)-1;
//End NeXTenesio3 Special List Recordset

// Make a logout transaction instance
$logoutTransaction = new tNG_logoutTransaction($conn_hitekforyou);
$tNGs->addTransaction($logoutTransaction);
// Register triggers
$logoutTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "GET", "KT_logout_now");
$logoutTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "login.php");
// Add columns
// End of logout transaction instance

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rscustom = $tNGs->getRecordset("custom");
$row_rscustom = mysql_fetch_assoc($rscustom);
$totalRows_rscustom = mysql_num_rows($rscustom);

$nav_listchitietdonhang1->checkBoundries();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="quantri.css" rel="stylesheet" type="text/css" />
<script src="../AC_RunActiveContent.js" type="text/javascript"></script>

<title>Quản trị web HitekForYou</title>
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style><script src="../includes/nxt/scripts/list.js" type="text/javascript"></script><script src="../includes/nxt/scripts/list.js.php" type="text/javascript"></script><script type="text/javascript">
$NXT_LIST_SETTINGS = {
  duplicate_buttons: true,
  duplicate_navigation: true,
  row_effects: true,
  show_as_buttons: true,
  record_counter: true
}
</script><style type="text/css">
  /* Dynamic List row settings */
  .KT_col_idChitiet {
	width:80px;
	overflow:hidden;
}
  .KT_col_idDH {
	width:80px;
	overflow:hidden;
}
  .KT_col_idSP {
	width:100px;
	overflow:hidden;
}
  .KT_col_SoLuong {
	width:80px;
	overflow:hidden;
}
  .KT_col_DonGia {width:140px; overflow:hidden;}
</style>

</head>

<body>

<?php include("admin_template/header.php"); ?>
<?php include("admin_template/admin_banner.php"); ?>  
<table id="main" width="990" border="1" align="center" cellpadding="0" cellspacing="0">
 <tr>
    <td width="200" align="left" valign="top" bgcolor="#66CC00" id="cottrai">
      <div align="left">
      <?php include("menu.php"); ?>  
      </div>       </td>
    <td id="cotphai" width="790" align="left" valign="top" bgcolor="#FFFFFF">
    
<div class="KT_tng" id="listchitietdonhang1">
  <h1> Danh sách chi tiết đơn hàng
    <?php
  $nav_listchitietdonhang1->Prepare();
  require("../includes/nav/NAV_Text_Statistics.inc.php");
?>
  </h1>
  <div class="KT_tnglist">
    <form action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" method="post" id="form1">
      <div class="KT_options"> <a href="<?php echo $nav_listchitietdonhang1->getShowAllLink(); ?>">Hiện
            <?php 
  // Show IF Conditional region1
  if (@$_GET['show_all_nav_listchitietdonhang1'] == 1) {
?>
            <?php echo $_SESSION['default_max_rows_nav_listchitietdonhang1']; ?>
            <?php 
  // else Conditional region1
  } else { ?>
            tất cả
            <?php } 
  // endif Conditional region1
?>
            dữ liệu</a> &nbsp;
        &nbsp;
                            <?php 
  // Show IF Conditional region2
  if (@$_SESSION['has_filter_tfi_listchitietdonhang1'] == 1) {
?>
                            <a href="<?php echo $tfi_listchitietdonhang1->getResetFilterLink(); ?>">Đóng bộ lọc</a>
                            <?php 
  // else Conditional region2
  } else { ?>
                            <a href="<?php echo $tfi_listchitietdonhang1->getShowFilterLink(); ?>">Hiện bộ lọc</a>
                            <?php } 
  // endif Conditional region2
?>
      </div>
      <table cellpadding="2" cellspacing="0" class="KT_tngtable">
        <thead>
          <tr class="KT_row_order">
            <th> <input type="checkbox" name="KT_selAll" id="KT_selAll"/>
            </th>
            <th id="idChitiet" class="KT_sorter KT_col_idChitiet <?php echo $tso_listchitietdonhang1->getSortIcon('chitietdonhang.idChitiet'); ?>"> <a href="<?php echo $tso_listchitietdonhang1->getSortLink('chitietdonhang.idChitiet'); ?>">ID Chi tiết ĐH</a> </th>
            <th id="idDH" class="KT_sorter KT_col_idDH <?php echo $tso_listchitietdonhang1->getSortIcon('donhang.idDH'); ?>"> <a href="<?php echo $tso_listchitietdonhang1->getSortLink('donhang.idDH'); ?>">ID Đơn hàng</a> </th>
            <th id="idSP" class="KT_sorter KT_col_idSP <?php echo $tso_listchitietdonhang1->getSortIcon('sanpham.TenSP'); ?>"> <a href="<?php echo $tso_listchitietdonhang1->getSortLink('sanpham.TenSP'); ?>">Sản phẩm</a> </th>
            <th id="SoLuong" class="KT_sorter KT_col_SoLuong <?php echo $tso_listchitietdonhang1->getSortIcon('chitietdonhang.SoLuong'); ?>"> <a href="<?php echo $tso_listchitietdonhang1->getSortLink('chitietdonhang.SoLuong'); ?>">Số lượng</a> </th>
            <th id="DonGia" class="KT_sorter KT_col_DonGia <?php echo $tso_listchitietdonhang1->getSortIcon('sanpham1.DonGia'); ?>"> <a href="<?php echo $tso_listchitietdonhang1->getSortLink('sanpham1.DonGia'); ?>">Đơn giá</a> </th>
            <th>&nbsp;</th>
          </tr>
          <?php 
  // Show IF Conditional region3
  if (@$_SESSION['has_filter_tfi_listchitietdonhang1'] == 1) {
?>
          <tr class="KT_row_filter">
            <td>&nbsp;</td>
            <td><input type="text" name="tfi_listchitietdonhang1_idChitiet" id="tfi_listchitietdonhang1_idChitiet" value="<?php echo KT_escapeAttribute(@$_SESSION['tfi_listchitietdonhang1_idChitiet']); ?>" size="20" maxlength="100" /></td>
            <td><select name="tfi_listchitietdonhang1_idDH" id="tfi_listchitietdonhang1_idDH">
              <option value="" <?php if (!(strcmp("", @$_SESSION['tfi_listchitietdonhang1_idDH']))) {echo "SELECTED";} ?>><?php echo NXT_getResource("None"); ?></option>
              <?php
do {  
?>
              <option value="<?php echo $row_Recordset2['idDH']?>"<?php if (!(strcmp($row_Recordset2['idDH'], @$_SESSION['tfi_listchitietdonhang1_idDH']))) {echo "SELECTED";} ?>><?php echo $row_Recordset2['idDH']?></option>
              <?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
  $rows = mysql_num_rows($Recordset2);
  if($rows > 0) {
      mysql_data_seek($Recordset2, 0);
	  $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  }
?>
            </select>
            </td>
            <td><select name="tfi_listchitietdonhang1_idSP" id="tfi_listchitietdonhang1_idSP">
              <option value="" <?php if (!(strcmp("", @$_SESSION['tfi_listchitietdonhang1_idSP']))) {echo "SELECTED";} ?>><?php echo NXT_getResource("None"); ?></option>
              <?php
do {  
?>
              <option value="<?php echo $row_Recordset3['idSP']?>"<?php if (!(strcmp($row_Recordset3['idSP'], @$_SESSION['tfi_listchitietdonhang1_idSP']))) {echo "SELECTED";} ?>><?php echo $row_Recordset3['TenSP']?></option>
              <?php
} while ($row_Recordset3 = mysql_fetch_assoc($Recordset3));
  $rows = mysql_num_rows($Recordset3);
  if($rows > 0) {
      mysql_data_seek($Recordset3, 0);
	  $row_Recordset3 = mysql_fetch_assoc($Recordset3);
  }
?>
            </select>
            </td>
            <td><input type="text" name="tfi_listchitietdonhang1_SoLuong" id="tfi_listchitietdonhang1_SoLuong" value="<?php echo KT_escapeAttribute(@$_SESSION['tfi_listchitietdonhang1_SoLuong']); ?>" size="20" maxlength="100" /></td>
            <td>&nbsp;</td>
            <td><input type="submit" name="tfi_listchitietdonhang1" value="Lọc" /></td>
          </tr>
          <?php } 
  // endif Conditional region3
?>
        </thead>
        <tbody>
          <?php if ($totalRows_rschitietdonhang1 == 0) { // Show if recordset empty ?>
          <tr>
            <td colspan="7"><?php echo NXT_getResource("Dữ liệu đang rỗng hoặc từ khóa lọc của bạn quá dài."); ?></td>
          </tr>
          <?php } // Show if recordset empty ?>
          <?php if ($totalRows_rschitietdonhang1 > 0) { // Show if recordset not empty ?>
          <?php do { ?>
          <tr class="<?php echo @$cnt1++%2==0 ? "" : "KT_even"; ?>">
            <td><input type="checkbox" name="kt_pk_chitietdonhang" class="id_checkbox" value="<?php echo $row_rschitietdonhang1['idChitiet']; ?>" />
                <input type="hidden" name="idChitiet" class="id_field" value="<?php echo $row_rschitietdonhang1['idChitiet']; ?>" />
            </td>
            <td><div class="KT_col_idChitiet"><?php echo KT_FormatForList($row_rschitietdonhang1['idChitiet'], 20); ?></div></td>
            <td><div class="KT_col_idDH"><?php echo KT_FormatForList($row_rschitietdonhang1['idDH'], 20); ?></div></td>
            <td><div class="KT_col_idSP"><?php echo KT_FormatForList($row_rschitietdonhang1['idSP'], 20); ?></div></td>
            <td><div class="KT_col_SoLuong"><?php echo KT_FormatForList($row_rschitietdonhang1['SoLuong'], 20); ?></div></td>
            <td><div class="KT_col_DonGia"><?php echo KT_FormatForList($row_rschitietdonhang1['DonGia'], 20); ?></div></td>
            <td><a class="KT_edit_link" href="FormChiTietDH.php?idChitiet=<?php echo $row_rschitietdonhang1['idChitiet']; ?>&amp;KT_back=1">Sửa</a> <a class="KT_delete_link" href="#delete">Xóa</a> </td>
          </tr>
          <?php } while ($row_rschitietdonhang1 = mysql_fetch_assoc($rschitietdonhang1)); ?>
          <?php } // Show if recordset not empty ?>
        </tbody>
      </table>
      <div class="KT_bottomnav">
        <div>
          <?php
            $nav_listchitietdonhang1->Prepare();
            require("../includes/nav/NAV_Text_Navigation.inc.php");
          ?>
        </div>
      </div>
      <div class="KT_bottombuttons">
        <div class="KT_operations"> <a class="KT_delete_op_link" href="#" onclick="nxt_list_delete_link_form(this); return false;">Xóa nhiều</a> </div>
        <span>&nbsp;</span>
       
        <a class="KT_additem_op_link" href="FormChiTietDH.php?KT_back=1" onclick="return nxt_list_additem(this)">Thêm</a> </div>
    </form>
  </div>
  <br class="clearfixplain" />
</div>
<p>&nbsp;</p>

 </tr>
</table>
<?php include("admin_template/footer.php"); ?>  
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);

mysql_free_result($Recordset3);

mysql_free_result($Recordset4);

mysql_free_result($rschitietdonhang1);
?>

